//
#import "BKFramework.h"
#import "BKSignatures.h"

@implementation BKFramework

- (id) initWithPath: (NSString*) path
{
	if(self = [super init])
	{
		_path = [path copy];
		//_bundle = [[NSBundle alloc] initWithPath: _path];
		_bundle = CFBundleCreate(NULL, (CFURLRef) [NSURL fileURLWithPath: _path isDirectory: YES]);
		if(_bundle == NULL)
		{
			[self dealloc];
			return nil;
		}
		//[_bundle load];
		CFBundleLoadExecutable(_bundle);
		
		NSString* fw = [path lastPathComponent];
		if([fw hasSuffix: @".framework"])
			fw = [fw substringToIndex: [fw length] - 10];
		_name = [fw copy];
		
		NSString* str = [path stringByAppendingPathComponent: 
			[NSString stringWithFormat: @"Resources/BridgeSupport/%@.bridgesupport", fw]];
		NSURL* url = [NSURL fileURLWithPath: str isDirectory: NO];
		
		NSXMLDocument* doc = [[[NSXMLDocument alloc] initWithContentsOfURL: url options: 0 error: nil] autorelease];
		if(doc == nil)
		{
			[self dealloc];
			return nil;
		}
		
		_signatures = [[BKSignatures signaturesWithXMLElement: [doc rootElement] framework: self] retain];
	}
	return self;
}

- (void) dealloc
{
	[_name release];
	[_path release];
	//[_bundle release];
	if(_bundle)
		CFRelease(_bundle);
	[_signatures release];
	[super dealloc];
}

@synthesize name = _name;
@synthesize path = _path;
@synthesize bundle = _bundle;
@synthesize signatures = _signatures;

@end
